package Q2;

import java.util.Arrays;

public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * max increasing subsequence
     * @param arr int整型一维数组 the array
     * @return int整型
     */
    public static int MLS (int[] arr) {
        // write code here

        int n = arr.length;

        Arrays.sort(arr);

//        int preIndex = 0, curIndex = 1;
        int ret = 1;

//        while (curIndex < n) {
//            while (curIndex < n && arr[curIndex] - arr[curIndex - 1] == 1) {
//                curIndex++;
//            }
//            ret = Math.max(ret, curIndex - preIndex);
//            preIndex = curIndex;
//            curIndex++;
//        }

        int count = 0;
        int preIndex = 0;
        for (int i = 1; i <= n; i++) {
            if (i < n && arr[i] - arr[i - 1] == 1) {
                count++;
            } else {
                ret = Math.max(ret, i - preIndex);
                count = 0;
                preIndex = i;
            }
        }

        return ret;
    }

    public static void main(String[] args) {
        System.out.println(MLS(new int[]{1,2,4,5,6,7,8,9,10}));
    }
}
